package cn.zn.modules.loan.old.service.impl;

import cn.zn.modules.loan.old.entity.TLoanDetailEntity;
import cn.zn.modules.loan.old.inter.LoanInter;
import cn.zn.modules.loan.old.inter.vo.LoanDetailVO;
import cn.zn.modules.loan.old.service.TLoanDetailService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class LoanInterImpl implements LoanInter {

    @Autowired
    private TLoanDetailService tLoanDetailService;

    @Override
    public Double findLoan(String applyCode) {
        TLoanDetailEntity tLoanDetailEntity = tLoanDetailService.findByApplyCode(applyCode);
        if (tLoanDetailEntity != null) {
            return tLoanDetailEntity.getLoanAmount();
        }
        return null;
    }

    @Override
    public LoanDetailVO findByApplyCode(String applyCode) {
        TLoanDetailEntity loanDetailEntity = tLoanDetailService.getOne(new QueryWrapper<TLoanDetailEntity>().eq("APPLY_CODE_", applyCode));
        if (loanDetailEntity == null) {
            return null;
        }
        LoanDetailVO loanDetailVO = new LoanDetailVO();
        BeanUtils.copyProperties(loanDetailEntity, loanDetailVO);
        return loanDetailVO;
    }

    @Override
    public List<LoanDetailVO> findByApplyCodes(List<String> applyCodes) {
        return tLoanDetailService.findByApplyCode(applyCodes).stream().map(o -> {
            LoanDetailVO loanDetailVO = new LoanDetailVO();
            BeanUtils.copyProperties(o, loanDetailVO);
            return loanDetailVO;
        }).collect(Collectors.toList());
    }

    @Override
    public List<LoanDetailVO> findByUserId(String userId, Boolean isLoan) {
        return null;
    }

    @Override
    public void saveLoan(LoanDetailVO loanDetailVO) {

    }
}
